package com.leadbank.security.hello.service;

import java.util.List;

import com.leadbank.security.hello.dao.EmployeeDao;
import com.leadbank.security.hello.model.Employee;
import com.leadbank.security.hello.model.EmployeeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EmployeeManagerImpl implements EmployeeManager {
	
	@Autowired
    private EmployeeDao employeeDAO;

	@Override
	@Transactional
	public void addEmployee(Employee employee) {
		employeeDAO.insert(employee);
	}

	@Override
	@Transactional
	public List<Employee> getAllEmployees() {
		return employeeDAO.selectByExample(null);
	}

	@Override
	@Transactional
	public void deleteEmployee(Integer employeeId) {
		EmployeeExample employeeExample = new EmployeeExample();
		employeeExample.or().andIdEqualTo(employeeId);
		employeeDAO.deleteByExample(employeeExample);
	}

	public void setEmployeeDAO(EmployeeDao employeeDAO) {
		this.employeeDAO = employeeDAO;
	}
}
